package com.ruix.app.ui.adapter;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.Log;

import com.ruix.app.R;
import com.ruix.app.adapter.superadapter.SuperAdapter;
import com.ruix.app.adapter.superadapter.internal.SuperViewHolder;
import com.ruix.app.model.Comment;
import com.ruix.app.util.DateUtil;

/**
 * Created by hadexs on 2017/4/25.
 */

public class NoticeDetailCommentAdapter extends SuperAdapter<Comment> {


    private int authorColor;

    public NoticeDetailCommentAdapter(Context context) {
        super(context, R.layout.item_notice_comment);
        authorColor = context.getResources().getColor(R.color.green);
    }

    @Override
    public void onBind(SuperViewHolder holder, int viewType, int position, Comment item) {
        String comment = item.getAuthorName() + ":" + item.getContent();//TODO
        int autherSize = item.getAuthorName().length() + 1;
        holder.setText(R.id.tv_comment_comtent, spannableString(comment, autherSize));
        String timeString = DateUtil.createMsgTimeStyle(item.getCreatTime());
        holder.setText(R.id.tv_comment_time, timeString);
    }

    private SpannableStringBuilder spannableString(String str, int length) {
        SpannableStringBuilder style = new SpannableStringBuilder(str);
        ForegroundColorSpan auatherSpan = new ForegroundColorSpan(authorColor);
        style.setSpan(auatherSpan, 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return style;
    }
}
